const app = getApp()
var staticUrl = 'http://07.imgmini.eastday.com/mobile/20180422/20180422152349_9ce9e6119bcf986ff2fe20366125127c_1.jpeg';
Page({
  data: {
    navbar: ['病友分享', '我的文章'],
    currentTab: 0,
    avatarUrl: '',
    isHiddenSharedArticleList:false,
    isHiddenSharedArticleDetail:true,
    isHiddenMyArticleList:false,
    isHiddenMyArticleDetail:true,

    goBack:'<返回',
    sharedArticleDetailTitle:'感恩的心',
    sharedArticleDetailAuthor:'佚名',
    sharedArticleDetailTime:'2018-08-05',
    sharedArticleDetailContent:'感恩的心，感谢有你',
    myArticleDetailTitle:'感恩的心',
    myArticleDetailContent: '感恩的心，感谢有你',
    isHiddenModiAndDelBtn:false,
    isHiddenAddBtn:true,
    sharedArticleItems: [{
        id: '1', //文章id
        uid: '2', //作者id
        imgUrl: staticUrl, //图片url
        title: '床前明月光', //标题
        details: '123123', //文章内容
        time: '2018-03-05', //文章发布时间
        author: '孙加辉'
        //abstract:'',//摘要
      },
      {
        id: '2', //文章id
        uid: '2', //作者id
        imgUrl: staticUrl, //图片url
        title: '奥术大师大所大所', //标题
        details: '456456', //文章内容
        time: '2018-05-05', //文章发布时间
        author:'啦啦啦',
        //abstract:'',//摘要
      },
      {
        id: '3', //文章id
        uid: '2', //作者id
        imgUrl: staticUrl, //图片url
        title: '爱仕达多撒所大所大', //标题
        details: '789789', //文章内容
        time: '2018-05-02', //文章发布时间
        author: '啦啦啦1',
        //abstract:'',//摘要
      },
      {
        id: '4', //文章id
        uid: '2', //作者id
        imgUrl: staticUrl, //图片url
        title: '奥术大师大所大所多', //标题
        details: '789456', //文章内容
        time: '2018-05-06', //文章发布时间
        author: '啦啦啦2',
        //abstract:'',//摘要
      },
    ],
    myArticleItems: [{
        id: '1', //文章id
        uid: '2', //作者id
        imgUrl: staticUrl, //图片url
        title: '床前明月光', //标题
        details: '', //文章内容
        time: '2018-03-05', //文章发布时间
        state:'审核中',
        color:'orange',
        //abstract:'',//摘要
      },
      {
        id: '2', //文章id
        uid: '2', //作者id
        imgUrl: staticUrl, //图片url
        title: '奥术大师大所大所', //标题
        details: '', //文章内容
        time: '', //文章发布时间
        state: '未通过审核',
        color: 'red',
        //abstract:'',//摘要
      },
      {
        id: '3', //文章id
        uid: '2', //作者id
        imgUrl: staticUrl, //图片url
        title: '奥术大师大所大所', //标题
        details: '', //文章内容
        time: '', //文章发布时间
        state: '审核通过',
        color: 'green',
        //abstract:'',//摘要
      }
    ]
  },

  onLoad: function() {
    wx.setNavigationBarTitle({
      title: app.globalData.Titles[6] //页面标题为路由参数
    })

  },
  //切换页面
  navbarTap: function(e) {
    var that = this;
    that.setData({
      currentTab: e.currentTarget.dataset.idx
    })
  },
  //点击响应
  tapName: function(event) {
    //console.log(event.currentTarget.id)
    if (event.currentTarget.id =='goBackToSharedList'){
      this.backToShareList();
    } else if (event.currentTarget.id == 'goBackToMyList') {
      this.backToMyList();
    }
    else{
      this.toDetail(event.currentTarget.id);
      this.goToShareDetail();
    }
  },
  //回到病友分享文章列表页面
  backToShareList:function(){
    var that = this;
    that.setData({
      isHiddenSharedArticleList: false,
      isHiddenSharedArticleDetail: true,
    })
  },
  //回到我的文章列表页面
  backToMyList: function () {
    var that = this;
    that.setData({
      isHiddenMyArticleList: false,
      isHiddenMyArticleDetail: true,
    })
  },
  //回到病友分享文章详情页面
  goToShareDetail: function () {
    var that = this;
    that.setData({
      isHiddenSharedArticleList: true,
      isHiddenSharedArticleDetail: false,
    })
  },
  //回到我的文章详情页面
  goToMyDetail: function (id) {
    console.log(id)
    var that = this;
    that.setData({
      isHiddenMyArticleList: true,
      isHiddenMyArticleDetail: false,
    })
  },
  //设置病友分享文章详情页面的内容
  toDetail:function(id){
    var that = this;
    var item = that.data.sharedArticleItems[id - 1];
    that.setData({
      sharedArticleDetailTitle: item.title,
      sharedArticleDetailAuthor: item.author,
      sharedArticleDetailTime: item.time,
      sharedArticleDetailContent: item.details,
    })
    //console.log(that.data.sharedArticleItems[id-1])
  },
  //创建新文章
  createNewArticle:function(event){
    //console.log("添加")
    var that = this ;
    that.setData({
      isHiddenModiAndDelBtn: true,
      isHiddenAddBtn: false,
    })
    this.goToMyDetail(0)
  },
  //修改文章
  modiAriticle:function(event){
    var that = this;
    that.setData({
      isHiddenModiAndDelBtn: false,
      isHiddenAddBtn: true,
    })
    this.goToMyDetail(event.currentTarget.id)
  },
  //删除文章
  delArticle:function(){
    console.log("删除")
  },
  //提交文章
  articleSubmit:function(){
    console.log("提交")
  },
  //获取所有用户文章
  getAllSharedArticles:function(){
    
  }


})